<template>
  <div class="app-container" v-loading.fullscreen.lock="loading">
    <Taskhead
      v-if="bindexamdata.length > 0"
      @getexamid="getexamid"
      :bindexamdata="bindexamdata"
      @geturldata="geturldata"
      @qhsubject="qhsubject"
    ></Taskhead>
    <component
      v-if="xmxx.id&&examsubjectid"
      ref="component"
      :tasklist="tasklist"
      @taskshooltap="taskshooltap"
      @refresh="refresh"
      @rowreviewrounds="rowreviewrounds"
      @gobacktop="gobacktop"
      :examsubjectid="examsubjectid"
      :is="activeTab"
      @taskwaytap="taskwaytap"
      :xmxx="xmxx"
      :pyjdData="pyjdData"
    ></component>
  </div>
</template>

<script>
import Taskhead from "../../components/task/taskhead.vue";
import { taskOverviewlist, getReviewStatus } from "@/api/task/task.js";
import { modellistsubject } from "@/api/paperinfo/paperinfo.js";
import { getSubjectList } from "@/api/xmgl/pyjd";
import Taskoverview from "./components/taskover.vue";
import Evaluationcoefficient from "./components/evaluationcoefficient.vue";
import Schoolallocationsituation from "./components/schoolallocationsituation.vue";
import Taskteacher from "./components/taskteacher.vue";
export default {
  name: "Project_taskoverview",
  components: {
    Taskoverview: Taskoverview,
    Evaluationcoefficient: Evaluationcoefficient,
    Schoolallocationsituation: Schoolallocationsituation,
    Taskteacher: Taskteacher,
  },
  data() {
    return {
      loading: false,
      tasklist: [],
      total: 0,
      bindexamdata: [],
      activeTab: this.$auth.hasRole("admin")
        ? "Taskoverview"
        : "Schoolallocationsituation",
      examsubjectid: 0,
      xmxx: {},

      pyjdData: {},
    };
  },
  components: {
    Taskhead,
    Taskoverview,
    Evaluationcoefficient,
    Schoolallocationsituation,
    Taskteacher,
  },
  mounted() {
    this.loading = true;
    this.$store
      .dispatch("getXmxx")
      .then((res) => {
        this.xmxx = res;
        this.addmodelsubject(res.id);
      })
      .catch(() => {
        loading = false;
      });
  },
  methods: {
    //二评
    rowreviewrounds(data) {
      this.gettaskoverlisttap(this.examsubjectid);
    },
    //一键分配
    taskwaytap() {
      this.gettaskoverlisttap(this.examsubjectid);
    },
    //刷新
    refresh(data) {
      if (
        this.activeTab == "Taskoverview" ||
        this.activeTab == "Evaluationcoefficient"
      ) {
        this.gettaskoverlisttap(this.examsubjectid);
      }
    },
    //考试切换
    qhsubject(data) {
      console.info(data);
      this.examsubjectid = data.id;
      if (
        data.tabnumber == "Taskoverview" ||
        data.tabnumber == "Evaluationcoefficient"
      ) {
        this.gettaskoverlisttap(data.id);
      } else {
        if (this.$refs.component.schooltassklisttab) {
          this.$refs.component.schooltassklisttab();
        }
      }
    },
    taskshooltap(data) {
      this.activeTab = data;
    },
    gobacktop(data) {
      this.activeTab = data;
    },
    geturldata(data) {
      this.activeTab = data.tabnumber;
      this.refresh();
    },
    //获取考试id
    getexamid(examid) {
      //     this.gettaskoverlisttap(examid)
    },
    //获取任务总览列表
    gettaskoverlisttap(id) {
      this.loading = true;
      getReviewStatus({
        examId: id,
      })
        .then((res) => {
          this.pyjdData = {
            reviewStatus: res.data,
          };
          let obj = {
            examId: id,
          };
          taskOverviewlist(obj)
            .then((res) => {
              console.info(res);
              if (res.code == 200) {
                this.tasklist = res.data;
                this.total = res.total;
              }
            })
            .finally(() => {
              this.loading = false;
            });
        })
        .catch(() => {
          this.loading = false;
        });
    },
    addmodelsubject(id) {
      let obj = { examId: id };

      const init = (data) => {
        this.bindexamdata = data;
        this.examsubjectid = data[0].id;
        this.examIdData = data[0].examId;
        this.gettaskoverlisttap(data[0].id);
        sessionStorage.setItem("examSubjectId", data[0].id);
      };

      if (
        this.$auth.hasRole("admin") ||
        this.$auth.hasExamPermi("reviewing:teachers:xxfpqk")
      ) {
        getSubjectList(obj).then((res) => {
          if (res.code == 200) {
            init(res.rows);
          }
        });
      } else if (this.$auth.hasExamPermi("reviewing:teachers:xxfpqkkm")) {
        init(
          this.$store.state.xmgl.examSubjects.map((item) => {
            return {
              ...item,
              id: item.examSubjectId,
              name: item.examSubjectName,
            };
          })
        );
      }
    },
  },
};
</script>

<style scoped>
</style>